package com.hornsun.apply;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.*;

/**
 * <p>
 * 该文件的作用：//TODO
 * </p>
 *
 * @author xuxin
 * @date 2018/9/11
 */
@Component
public class PayConfig extends WXPayConfig {

    private byte[] certData;

    @Value("${account.appId}")
    private String appId;

    @Value("${account.mchId}")
    private String mchId;

    @Value("${account.secret}")
    private String secret;

    @Value("${account.certPath}")
    private String certPath;

    @Value("${account.trade_type}")
    private String tradeType;

    @Value("${account.fee_type}")
    private String feeType;

    @Value("${account.body}")
    private String body;

    @Value("${account.device_info}")
    private String deviceInfo;

    @Value("${account.notify_url}")
    private String notifyUrl;

    @Value("${account.undefine_url_suffix}")
    private String undefinedUrlSuffix;

    @Override
    public InputStream getCertStream() {
        File file = new File(this.certPath);
        InputStream certStream;
        try {
            certStream = new FileInputStream(file);
            this.certData = new byte[(int) file.length()];
            certStream.read(this.certData);
            certStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    @Override
    public IWXPayDomain getWXPayDomain() {
        return null;
    }

    @Override
    public String getAppID() {
        return appId;
    }

    @Override
    public String getMchID() {
        return mchId;
    }

    @Override
    public String getKey() {
        return secret;
    }

    public String getTradeType() {
        return tradeType;
    }

    public String getFeeType() {
        return feeType;
    }

    public String getBody() {
        return body;
    }

    public String getDeviceInfo() {
        return deviceInfo;
    }

    public String getNotifyUrl() {
        return notifyUrl;
    }

    public String getUndefinedUrlSuffix() {
        return undefinedUrlSuffix;
    }
}
